<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>泸职旅游-搜索</title>
    <link rel="stylesheet" type="text/css" href="css/common.css">
    <link rel="stylesheet" href="css/search.css">
    <script src="js/jquery-3.3.1.js"></script>
    <script src="js/getParameter.js"></script>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <script src="js/bootstrap.min.js"></script>


    <script>
        $(function () {
               var cid = getParameter("cid");
               console.log("cid:"+cid)
               var rname = getParameter("rname");
               console.log("rname:"+rname)
               if (rname){
                   rname=window.decodeURIComponent(rname);
               }
                load(cid,null,rname);
                //获取天气
               function fff(city){
                   $.post("comment/getWeather",{city:city},function (data) {
                        data = JSON.parse(data);
                       $("#area").html(data.city);//城市名
                       console.log("city:"+data.city)
                       $("#quality").html(data.aqi);//空气质量
                       console.log("aqi:"+data.aqi)
                       $("#temperature").html(data.temp);//气温
                       console.log("temp:"+data.temp)
                       $("#sd").html(data.humidity);//湿度
                       $("#weather").html(data.weather);//天气状况
                       $("#weather_pic").prop("src","img/"+data.img+".png");//天气图标
                       $("#wind_direction").html(data.winddirect);//风向
                       let futureWeather = data.futureWeather;//未来七天天气状况

                       // let fu = $(".futureWeather img");
                       // for (let i = 0; i < fu.length; i++) {
                       //     alert(i);
                       //     fu[i].remove();
                       // }
                       var str = '';
                       for (let i = 0; i < futureWeather.length; i++) {
                           //alert(data.futureWeather[i]);
                           str += '<img style="width: 14%;float: left" src="img/'+data.futureWeather[i]+'.png"/>';

                       }
                       $("#futureWeather").html(str);

                   });
               }

            function  getQueryString(name) {
                var  reg =  new  RegExp( "(^|&)"  + name +  "=([^&]*)(&|$)" ,  "i" );
                var  r = window.location.search.substr(1).match(reg);
                if  ( r !=  null  ){
                    return  decodeURI(r[2]);
                } else {
                    return  null ;
                }
            }
            //用户输入城市点击以后
               $("#see").click(function () {
                   let city = $("#city").val();
                    fff(city);
               });

               var parameter = getQueryString("rname");
               if(parameter==null){
                   parameter="泸州";
               }
               //alert(parameter);
               fff(parameter);

            let parameter1 = getParameter("city");
            if (parameter1 != null && parameter1 != "") {
                if(confirm("您要搜索的城市是：" + parameter1)){
                    load(5,1,parameter1);
                }
            }


        })
        function load(cid,currentPage,rname) {
            $.post("route/pageQuery",{cid:cid,currentPage:currentPage,rname:rname},function (pb) {
                $("#totalPage").html(pb.totalPage);
                $("#totalCount").html(pb.totalCount);
                var lis="";
                var firstPage='<li onclick="javascript:load('+cid+',1,'+rname+')"><a href="javascript:void(0)">首页</a></li>'
                var befNum=pb.currentPage-1;
                if (befNum<=0){
                    befNum=1
                }
                var befPage='<li class="threeword"  onclick="load('+cid+','+befNum+',\''+rname+'\')"><a href="javascript:void(0)">上一页</a></li>'
                lis+=firstPage;
                lis+=befPage;
                var begin;
                var end;
                if (pb.totalPage<10){
                    begin=1;
                    end=pb.totalPage;
                }else {
                    begin=pb.currentPage-5;
                    end=pb.currentPage+4;
                    if (begin<1){
                        begin=1;
                        end=begin+9;
                    }
                    if (end>pb.totalPage){
                        end=pb.totalPage;
                        begin=end-1;
                    }
                }
                for (var i = begin; i <=end; i++) {
                    var li;
                    if (pb.currentPage==i){
                        li='<li class="curPage" onclick="load('+cid+','+i+',\''+rname+'\')"><a href="javascript:void(0)">'+i+'</a></li>'
                    }else {
                        li='<li onclick="load('+cid+','+i+',\''+rname+'\')"><a href="javascript:void(0)">'+i+'</a></li>'
                    }

                    lis+=li;
                }
               /* for (var i = 1; i <=pb.totalPage; i++) {
                    var li;
                    if (pb.currentPage==i){
                         li='<li class="curPage" onclick="load('+cid+','+i+')"><a href="javascript:void(0)">'+i+'</a></li>'
                    }else {
                        li='<li onclick="load('+cid+','+i+')"><a href="javascript:void(0)">'+i+'</a></li>'
                    }

                    lis+=li;
                }*/
                var lastPage='<li class="threeword" onclick="load('+cid+','+pb.totalPage+',\''+rname+'\')"><a href="javascript:void(0)">末页</a></li>';
                var preNum=pb.currentPage+1;
                var prePage='<li class="threeword" onclick="load('+cid+','+preNum+',\''+rname+'\')"><a href="javascript:void(0)">下一页</a></li>'
                lis+=prePage;
                lis+=lastPage;
                $("#pageNum").html(lis);
                var route=$("#route_lis");
                var route_lis="";
                for (var i = 0; i <pb.list.length; i++) {
                    var routee=pb.list[i];
                    var li='<li>\n' +
                        '                            <div class="img"><img src="'+routee.rimage+'" style="width: 299px;"></div>\n' +
                        '                            <div class="text1">\n' +
                        '                                <p>'+routee.rname+'</p>\n' +
                        '                                <br/>\n' +
                        '                                <p>'+routee.routeIntroduce+'</p>\n' +
                        '                            </div>\n' +
                        '                            <div class="price">\n' +
                        '                                <p class="price_num">\n' +
                        '                                    <span>&yen;</span>\n' +
                        '                                    <span>'+routee.price+'</span>\n' +
                        '                                    <span>起</span>\n' +
                        '                                </p>\n' +
                        '                                <p><a href="route_detail.html?rid='+routee.rid+'">查看详情</a></p>\n' +
                        '                            </div>\n' +
                        '                        </li>';
                    route_lis+=li;
                }
                route.html(route_lis);
                window.scrollTo(0,0)
            })
        }
    </script>
</head>
<body>
<!--引入头部-->
<div id="header"></div>
    <div class="page_one">
        <div class="contant">
            <div class="crumbs">
                <img src="" alt="">
                <p>泸职旅行<span>搜索结果</span></p>
            </div>
            <div class="xinxi clearfix">
                <div class="left">
                    <div class="header">
                        <span>商品信息</span>
                        <span class="jg">价格</span>
                    </div>
                    <ul id="route_lis">
                        
                    </ul>
                    <div class="page_num_inf">
                        <i></i> 共
                        <span id="totalPage"></span>页<span id="totalCount"></span>条
                    </div>
                    <div class="pageNum">
                        <ul id="pageNum">

                        </ul>
                    </div>
                </div>
                <div class="right">
                    <div class="top">
                        <input style="width: 170px;float: left" id="city" type="text" class="form-control" placeholder="输入城市查看天气信息">
<!--                        <div class="hot">HOT</div>-->
                        <input style="float: left" id="see" class="btn btn-default" type="button" value="查看">
                    </div>
                    <ul>
                        <li>
                            <div >
                                <img id="weather_pic" style="width: 30%;float: left" src="http://app1.showapi.com/weather/icon/night/00.png"/>
                            </div>
                            <div id="area" style="float: right;color: #0f0f0f;font-size: 20px;padding-top: 10px;padding-right: 60px;font-size: 23px">城市</div>
                        </li>
<!--                        <div style="float: left;color: #0f0f0f;font-size: 20px;padding-top: 20px;padding-right: 60px;padding-left: 5px">湿度</div>-->
                        <table  style="width: 100%;margin-top: 30px">
                            <tr>
                                <th style="font-size: 30px;color: #2aabd2">湿&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;度:</th>
                                <td style="font-size: 20px" align="left" id="sd"></td>
                            </tr>
                            <tr>
                                <th style="font-size: 30px;color: #d58512">气&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;温:</th>
                                <td style="font-size: 20px" id="temperature"></td>
                            </tr>
                            <tr>
                                <th style="font-size: 30px;color: #8d8d8e">风&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;向:</th>
                                <td style="font-size: 16px" id="wind_direction"></td>
                            </tr>
                            <tr>
                                <th style="font-size: 30px;color: #c9e2b3">空气质量:&nbsp;</th>
                                <td style="font-size: 20px" id="quality"></td>
                            </tr>
                            <tr>
                                <th style="font-size: 30px;color: #66afe9">天气状况:</th>
                                <td style="font-size: 18px" id="weather"></td>
                            </tr>
                            <tr>
                                <th style="font-size: 23px;color: #6993f9;padding-top: 5px" colspan="2" align="center">未来七天天气状况</th>
                            </tr>
                            <tr>
                                <td id="futureWeather" colspan="2" style="padding-top: 12px">
                                </td>
                            </tr>

                        </table>
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <!--引入头部-->
    <div id="footer"></div>
    <!--导入布局js，共享header和footer-->
    <script type="text/javascript" src="js/include.js"></script>
</body>

</html>